package com.akkainaction.tool.eventbus;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import com.akkainaction.tool.eventbus.actor.EventBusActor;
import com.akkainaction.tool.eventbus.bus.EventBusDemo;
import com.akkainaction.tool.eventbus.event.Event;

public class TestEventBusDemo {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        //创建一个Actor
        ActorRef eventBusActor = system.actorOf(Props.create(EventBusActor.class), "eventBusActor");
        //创建bus
        EventBusDemo bus = new EventBusDemo();
        //eventBusActor订阅类型为info的event
        bus.subscribe(eventBusActor, "info");
        //eventBusActor订阅类型为warn的event
        bus.subscribe(eventBusActor, "warn");
        //向总线发送类型为info的event
        bus.publish(new Event("info","Hello EventBus Info"));
        //向总线发送类型为warn的event
        bus.publish(new Event("warn","Hello EventBus Warn"));
        //向总线发送类型为debug的event
        bus.publish(new Event("debug","Hello EventBus Debug"));
        //eventBusActor取消订阅bus
        bus.unsubscribe(eventBusActor);
        bus.publish(new Event("info","Hello EventBus Info"));
        bus.publish(new Event("warn","Hello EventBus Warn"));
    }
}
